using UnityEngine;
using UnityEngine.UI;

public class UICueItem : UIShopItem
{
	private int _itemId;

	public Text btnText;

	public Text flagText;

	private int _price;

	public int itemId => _itemId;

	public void SetData(int itemId, string name, int price)
	{
		_itemId = itemId;
		_price = price;
		txtName.text = name;
		txtPrice.transform.parent.gameObject.SetActive(price > 0);
		txtPrice.text = price.ToString();
		Refresh();
	}

	public void Refresh()
	{
		btnGO.SetActive(value: false);
		flagText.gameObject.SetActive(value: false);
		if (_itemId == base.parentPanel.useCue)
		{
			btnGO.SetActive(value: false);
			flagText.gameObject.SetActive(value: true);
			return;
		}
		btnGO.SetActive(value: true);
		if (_price > 0)
		{
			Item item = ItemMgr.instance.GetItem(itemId);
			if (item != null)
			{
				btnText.text = "使用";
			}
			else
			{
				btnText.text = "获取";
			}
		}
		else
		{
			btnText.text = "使用";
		}
	}

	public override void OnClickBuy()
	{
		UnityEngine.Debug.Log("click buy");
		if (btnText.text.Equals("获取"))
		{
			if (ConstantData.chips >= _price)
			{
				ItemMgr.instance.AddItem(itemId);
				base.parentPanel.useCue = itemId;
				base.parentPanel.RefreshCueList();
				ConstantData.chips -= _price;
			}
			else
			{
				base.parentPanel.OpenNotEnoughWnd();
			}
		}
		else if (btnText.text.Equals("使用"))
		{
			base.parentPanel.useCue = itemId;
			base.parentPanel.RefreshCueList();
		}
	}
}
